package com.cykj.web.controller.posbiz;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.domain.BizFeesCharged;
import com.cykj.pos.service.IBizFeesChargedService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 流量费费用收取列Controller
 *
 * @author xuxiaolong
 * @date 2022-04-29
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/fees/charged" )
public class BizFeesChargedController extends BaseController {

    private final IBizFeesChargedService iBizFeesChargedService;

    /**
     * 查询流量费费用收取列列表
     */
    @PreAuthorize("@ss.hasPermi('fees:charged:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizFeesCharged bizFeesCharged) {
        startPage();
        List<BizFeesCharged> list = iBizFeesChargedService.queryList(bizFeesCharged);
        return getDataTable(list);
    }

    /**
     * 导出流量费费用收取列列表
     */
    @PreAuthorize("@ss.hasPermi('fees:charged:export')" )
    @Log(title = "流量费费用收取列" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(BizFeesCharged bizFeesCharged) {
        List<BizFeesCharged> list = iBizFeesChargedService.queryList(bizFeesCharged);
        ExcelUtil<BizFeesCharged> util = new ExcelUtil<BizFeesCharged>(BizFeesCharged.class);
        return util.exportExcel(list, "charged" );
    }

    /**
     * 获取流量费费用收取列详细信息
     */
    @PreAuthorize("@ss.hasPermi('fees:charged:query')" )
    @GetMapping(value = "/{mamountId}" )
    public AjaxResult getInfo(@PathVariable("mamountId" ) String mamountId) {
        return AjaxResult.success(iBizFeesChargedService.getById(mamountId));
    }

    /**
     * 新增流量费费用收取列
     */
    @PreAuthorize("@ss.hasPermi('fees:charged:add')" )
    @Log(title = "流量费费用收取列" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizFeesCharged bizFeesCharged) {
        return toAjax(iBizFeesChargedService.save(bizFeesCharged) ? 1 : 0);
    }

    /**
     * 修改流量费费用收取列
     */
    @PreAuthorize("@ss.hasPermi('fees:charged:edit')" )
    @Log(title = "流量费费用收取列" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizFeesCharged bizFeesCharged) {
        return toAjax(iBizFeesChargedService.updateById(bizFeesCharged) ? 1 : 0);
    }

    /**
     * 删除流量费费用收取列
     */
    @PreAuthorize("@ss.hasPermi('fees:charged:remove')" )
    @Log(title = "流量费费用收取列" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{mamountIds}" )
    public AjaxResult remove(@PathVariable String[] mamountIds) {
        return toAjax(iBizFeesChargedService.removeByIds(Arrays.asList(mamountIds)) ? 1 : 0);
    }
}
